package com.ruoyi.report.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.ReportRecord;
import com.ruoyi.report.service.IReportRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报生成记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/report/record")
public class ReportRecordController extends BaseController
{
    private String prefix = "report/record";

    @Autowired
    private IReportRecordService reportRecordService;

    @RequiresPermissions("report:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询报生成记录列表
     */
    @RequiresPermissions("report:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportRecord reportRecord)
    {
        startPage();
        List<ReportRecord> list = reportRecordService.selectReportRecordList(reportRecord);
        return getDataTable(list);
    }

    /**
     * 导出报生成记录列表
     */
    @RequiresPermissions("report:record:export")
    @Log(title = "报生成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReportRecord reportRecord)
    {
        List<ReportRecord> list = reportRecordService.selectReportRecordList(reportRecord);
        ExcelUtil<ReportRecord> util = new ExcelUtil<ReportRecord>(ReportRecord.class);
        return util.exportExcel(list, "报生成记录数据");
    }

    /**
     * 新增报生成记录
     */
    @RequiresPermissions("report:record:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报生成记录
     */
    @RequiresPermissions("report:record:add")
    @Log(title = "报生成记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReportRecord reportRecord)
    {
        return toAjax(reportRecordService.insertReportRecord(reportRecord));
    }

    /**
     * 修改报生成记录
     */
    @RequiresPermissions("report:record:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        ReportRecord reportRecord = reportRecordService.selectReportRecordByRecordId(recordId);
        mmap.put("reportRecord", reportRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存报生成记录
     */
    @RequiresPermissions("report:record:edit")
    @Log(title = "报生成记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReportRecord reportRecord)
    {
        return toAjax(reportRecordService.updateReportRecord(reportRecord));
    }

    /**
     * 删除报生成记录
     */
    @RequiresPermissions("report:record:remove")
    @Log(title = "报生成记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reportRecordService.deleteReportRecordByRecordIds(ids));
    }
}
